/**=========================================================
 * Directive: simple-radio.js
 =========================================================*/

App.directive('simpleRadio', ['Utils',
    function(utils) {
        'use strict';
        
        return {
            restrict: 'EA',
            replace: true,
            template: function($element,$attrs){
                var optionModel = $attrs.optionModel || 'radioGroup',   
                    name = $attrs.name,
                    ngModel = '$parent.' + (utils.isEmpty($attrs.ngModel) ? ('radios.' + optionModel  + '.currentCheck') : $attrs.ngModel),
                    showName = $attrs.i18n == 'true' ? '{{$translate.instant(radio.name)}}' : '{{::radio.name}}';
                    
                if ($attrs.type == 'button'){
                    return '\
                        <div class="btn-group">\
                            <label class="btn btn-primary" style="padding: 6px" ng-repeat="radio in radios.' + optionModel + '.radioValues" ng-model="' + ngModel + '" uib-btn-radio="radio.value">\
                                ' + showName + '\
                            </label>\
                        </div>\
                        '
                }else{  
                    return '\
                        <label class="radio-inline c-radio" style="margin-left:20px" ng-repeat="radio in radios.' + optionModel + '.radioValues">\
                            <input type="radio" name="' + name + '" value="{{::radio.value}}" ng-checked="{{$first}}" ng-model="' + ngModel + '"/>\
                            <span class="fa fa-check"></span>\
                            ' + showName + '\
                        </label>\
                    '
                }
            }
        }
    }
]);